package web.controller.sys;

import com.github.pagehelper.PageInfo;
import framework.vo.ResultInfo;
import framework.vo.ResultList;
import io.swagger.annotations.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import system.entity.SysOperation;
import system.service.sys.SysOperationService;

@RestController
@RequestMapping("/sys/operation")
@Api(tags = "操作记录")
public class SysOperationController {
    @Autowired
    private SysOperationService sysOperationService;

    @ApiOperation("添加操作记录")
    @PostMapping("/add")
    public ResultInfo<Long> add(@ModelAttribute SysOperation param) {
        java.util.Date now = new java.util.Date();
        param.setCreateTime(now);
        Integer added = sysOperationService.add(param);
        ResultInfo<Long> info = new ResultInfo<>(param.getId());
        return info;
    }

    @ApiOperation("删除操作记录")
    @PostMapping("/del")
    public ResultInfo<Integer> del(@RequestParam("ids") List<Long> ids) {
        Integer deleted = sysOperationService.deleteByIds(ids);
        ResultInfo<Integer> info = new ResultInfo<>(deleted);
        return info;
    }

//    @ApiOperation("更新操作记录")
//    @PostMapping("/edit")
//    public ResultInfo<Integer> edit(@ModelAttribute SysOperation param) {
//        java.util.Date now = new java.util.Date();
//        Integer updated = sysOperationService.update(param);
//        ResultInfo<Integer> info = new ResultInfo<>(updated);
//        return info;
//    }

    @ApiOperation("查看操作记录")
    @GetMapping("/info")
    public ResultInfo<SysOperation> info(@RequestParam("id") Long id) {
        SysOperation info = sysOperationService.loadById(id);
        return new ResultInfo<>(info);
    }

    @ApiOperation("操作记录列表")
    @GetMapping("/list")
    public ResultList<SysOperation> list(SysOperation param, @RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<SysOperation> info = sysOperationService.list(param, pageIndex, pageSize);
        return new ResultList<>(info);
    }
}